home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_dates2.arc / SEPARATE.ARC / NEWDATE.C < prev   
Text File  |  1991-01-10  |  2KB  |  57 lines

  1. /************************************************************************/
  2. /*                *** newdate.c ***            */
  3. /*                                    */
  4. /* This function returns a new julian date, expressed as an unsigned    */
  5. /* long integer, arrived at by adding a    specified number of days of a    */
  6. /* specified type to the starting julian date input.            */
  7. /*                                    */
  8. /* In short, it adds days to a date to get a new date.            */
  9. /*                                    */
  10. /* The input values to the function, in their proper order, are:    */
  11. /*                                    */
  12. /*  1.  the beginning julian date              ( unsigned long )    */
  13. /*                                    */
  14. /*  2.  the number of days to be added              ( signed   long )    */
  15. /*                                    */
  16. /*  3.  the numerical code representing the type            */
  17. /*    of days    to be added ( described below )          ( unsigned int )    */
  18. /*                                    */
  19. /* The following is a list of the codes used to define the        */
  20. /* type of days that are to be added to the start date:            */
  21. /*                                    */
  22. /*   CODE        - EXPLANATION -                    */
  23. /*                                    */
  24. /*     0  -  weekdays and weekends (all days)                */
  25. /*                                    */
  26. /*     1  -  weekdays and Saturdays only (Sundays skipped over)        */
  27. /*                                    */
  28. /*     2  -  weekdays only (weekends skipped over)            */
  29. /*                                    */
  30. /*   NOTE -  input of any code not listed above will be            */
  31. /*         interpreted as code 0.                    */
  32. /*                                    */
  33. /************************************************************************/
  34.  
  35. extern int dow( unsigned long );
  36.  
  37. long newdate( juldte, days, incl )
  38.  
  39. long juldte, days;
  40. unsigned int incl;
  41.  
  42. {
  43.     int eff = 7 - ( incl = incl > 2 ? 0 : incl ), rvrse = 0;
  44.  
  45.     if ( !incl-- ) return( juldte + days );
  46.  
  47.     if ( days < 0 )
  48.     {
  49.          rvrse   = eff + 1;
  50.          juldte += !dow( juldte ) + 2 * ( incl && !( 6 - dow( juldte ) ) );
  51.     }
  52.     else juldte -= !dow( juldte ) + ( incl && !( dow( juldte ) % 6 ) );
  53.  
  54.     return( juldte + days / eff * 7 + days % eff + ++incl *
  55.           ( ( dow( juldte ) + days % eff - rvrse ) / ( eff + 1 ) ) );
  56. }
  57.